package com.atguigu.serviceedu.controller.front;


import com.atguigu.commonutils.R;
import com.atguigu.serviceedu.entity.EduCourse;
import com.atguigu.serviceedu.entity.EduTeacher;
import com.atguigu.serviceedu.service.EduCourseService;
import com.atguigu.serviceedu.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/serviceedu/teacherfront")
//@CrossOrigin
public class TeacherFrontController {

    @Autowired
    private EduTeacherService eduTeacherService;

    @Autowired
    private EduCourseService eduCourseService;

    ///分页查询讲师
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable("page")Long page,
                                 @PathVariable("limit")Long limit){
        Page<EduTeacher> teacherPage = new Page<EduTeacher>(page,limit);

        Map<String,Object>map =  eduTeacherService.getTeacherFrontList(teacherPage);

        //返回分页所有的数据

        return R.ok().data(map);
    }

    //通过id查询老师
    @GetMapping("getTeacherFrontInfoById/{teacherid}")
    public  R getTeacherFrontInfoById(@PathVariable("teacherid")String id){

        //根据讲师id查询信息
        EduTeacher teacher = eduTeacherService.getById(id);
        System.out.println(teacher);

        //根据id查询所讲课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",id);

        List<EduCourse> courseList = eduCourseService.list(wrapper);

        return R.ok().data("teacher",teacher).data("courseList",courseList);
    }
}
